package com.ktjy.test;

import com.ktjy.entity.CollectionEntity;
import com.ktjy.entity.Host;
import com.ktjy.entity.NullEntity;
import com.ktjy.entity.Pet;
import com.ktjy.service.PetService;
import com.ktjy.service.PetServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;

public class Main {
    @Test
    public void test1(){
        //1.创建spring上下文对象
        ApplicationContext context=
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        //2.获取我们想要对象
        Pet pet = (Pet)context.getBean("pet1");
        //3.使用对象
        pet.introduce();
    }

    @Test
    public void test2(){
        //1.创建spring上下文对象
        ApplicationContext context=
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        //2.获取我们想要对象
        Pet pet = (Pet)context.getBean("pet2");
        //3.使用对象
        pet.introduce();
    }
    @Test
    public void test3(){
        //1.创建spring上下文对象
        ApplicationContext context=
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        //2.获取我们想要对象
        Pet pet = (Pet)context.getBean("pet3");
        //3.使用对象
        pet.introduce();
    }

    @Test
    public void test4(){
        //1.创建spring上下文对象
        ApplicationContext context=
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        //2.获取我们想要对象
        CollectionEntity collectionEntity = (CollectionEntity)context.getBean("collectionEntity");
        //3.使用对象
        System.out.println(Arrays.asList(collectionEntity.getArray()));
        System.out.println(collectionEntity.getList());
        System.out.println(collectionEntity.getSet());
        System.out.println(collectionEntity.getMap());
        System.out.println(collectionEntity.getProp());

    }

    @Test
    public void test5(){
        //1.创建spring上下文对象
        ApplicationContext context=
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        //2.获取我们想要对象
        NullEntity nullEntity = (NullEntity)context.getBean("nullEntity");
        //3.使用对象
        System.out.println(nullEntity.getEmptyValue());
        System.out.println(nullEntity.getNullValue());
    }

    @Test
    public void test6(){
        //1.创建spring上下文对象
        ApplicationContext context=
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        //2.获取我们想要对象
        Host host = (Host)context.getBean("host1");
        //3.使用对象
        System.out.println(host.getName()+","+host.getPet().getName()+","+host.getPet().getAge());
    }
    @Test
    public void test7(){
        //1.创建spring上下文对象
        ApplicationContext context=
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        //2.获取我们想要对象
        Host host = (Host)context.getBean("host2");
        //3.使用对象
        System.out.println(host.getName()+","+host.getPet().getName()+","+host.getPet().getAge());
    }
    @Test
    public void test8(){
        //1.创建spring上下文对象
        ApplicationContext context=
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        //2.获取我们想要对象
        Host host = (Host)context.getBean("host3");
        //3.使用对象
        System.out.println(host.getName()+","+host.getPet().getName()+","+host.getPet().getAge());
    }

    @Test
    public void test9(){
        //1.创建spring上下文对象
        ApplicationContext context=
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        //2.获取我们想要对象
        PetService petService = (PetService)context.getBean("petService");

        petService.insert(new Pet());
    }

}
